﻿Option Explicit On
Option Strict On

Imports Microsoft.Xna.Framework.Input

Public Class CommandsClass

    Private Declare Function keybd_event Lib "user32" Alias "keybd_event" _
                                            (ByVal bVk As Integer, ByVal bScan As Byte, ByVal dwFlags As Long, _
                                            ByVal dwExtraInfo As Long) As Long

    Private Declare Sub mouse_event Lib "user32" Alias "mouse_event" _
                                            (ByVal dwFlags As MouseActions, ByVal dx As Integer, ByVal dy As Integer, _
                                             ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)

    Public Enum MouseActions
        LeftDown = &H2
        LeftUp = &H4
        MiddleDown = &H20
        MiddleUp = &H40
        RightDown = &H8
        RightUp = &H10
        MoveMouse = &H1
    End Enum


    Public Sub MoveCursor(ByVal xChange As Integer, ByVal yChange As Integer)

        mouse_event(MouseActions.MoveMouse, xChange, yChange, 0, 0)

    End Sub


    Public Sub PressKey(ByVal k As Keys)

        keybd_event(k, 0, 0, 0) 'Press

    End Sub


    Public Sub ReleaseKey(ByVal k As Keys)

        keybd_event(k, 0, 2, 0) 'Release

    End Sub


    Public Sub PressAndReleaseKey(ByVal k As Keys)

        PressKey(k)
        ReleaseKey(k)

    End Sub


    Public Sub activateMouseButton(ByVal Button As MouseActions)

        mouse_event(Button, 0, 0, 0, 1)

    End Sub

End Class
